package com.wanxi.util;

import com.wanxi.domain.dto.CouponType;
import org.springframework.core.convert.converter.Converter;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author LiuYuRong
 * @Date 2022/1/8 13:58
 * @Version 1.0
 * @Description
 */
public  class CouponTypeConverter implements Converter<String, CouponType> {
    private Map<String,CouponType> enumMap= new HashMap<>();

    public CouponTypeConverter() {
        for (CouponType type:CouponType.values()){
            enumMap.put(type.getType(),type);
        }
    }

    @Override
    public CouponType convert(String source) {
        CouponType couponType=enumMap.get(source);
        if (couponType==null){
            throw new IllegalArgumentException("没有这个枚举类型");
        }
        return couponType;
    }
}
